package com.snowy.framework.util;

import lombok.extern.slf4j.Slf4j;

import java.util.Random;
import java.util.UUID;

@Slf4j
public class UUIDUtil {
    public static void main(String[] args) {
        //System.out.println(getKeyId());
        for (int i = 0; i <2000 ; i++) {
            Runnable runnable=new Runnable(){

                @Override
                public void run() {
                    log.info(createOrderId());
                }
            };
            new Thread(runnable).start();

        }


    }

    public static Long getKeyId() {
        Random random = new Random();
        int n = random.nextInt(10);
        Long timeTemp = System.currentTimeMillis();
        return timeTemp +n;
    }

    public static String createOrderId() {
        int machineId = 1;//最大支持1-9个集群机器部署
        int hashCodeV = UUID.randomUUID().toString().hashCode();
        if(hashCodeV < 0) {//有可能是负数
            hashCodeV = - hashCodeV;
        }
        // 0 代表前面补充0
        // 4 代表长度为4
        // d 代表参数为正数型
        return machineId+String.format("%015d", hashCodeV);
    }


}
